//
//  WFChannelTableView.m
//  FAKER
//
//  Created by Jianwei on 15/11/4.
//  Copyright © 2015年 YHLai. All rights reserved.
//

#import "WFChannelTableView.h"

#import "FitHeader.h"
#import "AllHeader.h"
#import "WFChannelListModel.h"
#define ALL_DATA_URLSTRING @"http://iphone.myzaker.com/zaker/apps_v3.php?_appid=iphone&_version=6.4&act=getAllAppsData"
@implementation WFChannelTableView
//- (void)pushViewController
//{
//    
//}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _channelDataSourceArray = [NSMutableArray array];
        [self getData];
        _channelTableView = [[BaseClassTableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64 - 40) style:UITableViewStylePlain];
        _channelTableView.delegate = self;
        _channelTableView.dataSource = self;
        _channelTableView.tableFooterView = [[BaseClassView alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        [self addSubview:_channelTableView];
    }
    return self;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"channel";
    WFChannelTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[WFChannelTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        
        
//        cell.delegate = self;
    }
    cell.accessoryType = 1;
    cell.selectionStyle = 0;
    cell.model = _channelDataSourceArray[indexPath.row];
    return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _channelDataSourceArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60 * FITHEIGHT;
}
- (void)getData
{
    [InternetDataRequest getDataByString:ALL_DATA_URLSTRING BodyDic:nil WithDataBlock:^(id data) {
        NSArray *array = [[data objectForKey:@"data"] objectForKey:@"datas"];
        for (NSDictionary *dic in array)
        {
            WFChannelListModel *model = [[WFChannelListModel alloc]init];
            [model setValuesForKeysWithDictionary:dic];
            [_channelDataSourceArray addObject:model];
        }
        [_channelTableView reloadData];
    }];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.delegate pushSecondChannelViewController:_channelDataSourceArray[indexPath.row]];
}













@end
